<!--//This file is part of the store/retrieve project
//    (http://code.google.com/p/storeretrieve/).
//
//    Store/retrieve is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Store/retrieve is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with store/retrieve. If not, see <http://www.gnu.org/licenses/>.
//-->


<%@ page import="java.util.Properties,
		java.util.ArrayList,
		java.io.File,
		java.io.FileInputStream,
		org.w3c.dom.*,
		javax.xml.parsers.*,
		javax.xml.xpath.*,
		java.util.HashMap,
		java.lang.StringBuilder,
		java.util.Random"
%>

<%! 	
	Properties loadPropertiesByUser(String username) {
		Properties result = new Properties();
		File file = new File(getServletContext().getRealPath("/WEB-INF/conf/user-" + username + ".properties"));
		if(file.exists()) {
			try{
				result.load(new FileInputStream(file));
			} catch(Throwable ex) {
				result = null;		
			} finally {}	
		} else {
			result = null;
		}
		return result;
	}

	//Reads a text element in a meta.xml's DOM
	String getFieldValueFromMetaDOM(Document doc, String key) { 
		String result;
		try {
			XPath xpath = XPathFactory.newInstance().newXPath();
			XPathExpression expr = xpath.compile("/Container/" + ((String)key));
			NodeList nodes = (NodeList)(expr.evaluate(doc, XPathConstants.NODESET));
			if(nodes == null || nodes.getLength() == 0)  {
				result = "";
			} else {
				result = nodes.item(0).getTextContent();
				if(result == null) result = "";
			}

		} catch(Throwable ex) { 
			result = "";
			ex.printStackTrace();
		} finally {}
		return result;
	}

	String getIconLink(String icon, String href, String target) {
                StringBuilder o = new StringBuilder();
		o.append("<a href=\"");
		o.append(href);
		o.append("\" ");
		o.append("target=\"");
		o.append(target);
		o.append("\">");
		o.append("<img src=\"");
		o.append("resources/" + icon + ".png");
		o.append("\" /></a>");
 		return o.toString();
	}

	String getLogoHtml() {
		return "<a href=\"http://code.google.com/p/storeretrieve/\">" +
		   	"<img src=\"resources/logo-storeretrieve-small.png\" " +
			"alt=\"store/retrieve\"" +
			"style=\"float:right;margin:0 5px 0 0;\" />" +
			"</a>";

	}
%>
